<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>包租婆审批</title>
<link rel="stylesheet" href="../../css/bootstrap.min.css"> 
<style type="text/css">
	#landladyTable{
		width: 700px;
		margin-left: 200px;
		margin-top: 35px;
	}
	#firstTr{
		font-size:16px;
		font-weight:bold;
		color: RGB(91,192,222);
	}
	#iform{
		margin-top:100px;
	}
</style>
</head>
<body>
	<form id="iform" action="ensureLandlady.do" method="post" >
		<div style="height:150px;">
		<table id="landladyTable" class="table table-striped table-bordered">
			<tr id="firstTr">
				<td>用户名</td>
				<td>真实姓名</td>
				<td>身份证号</td>
				<td>提交时间</td>
				<td>操作</td>
			</tr>
		</table>
		</div>
		<div style="margin-top:80px;">
		<ul class="pager">
			<!-- 这个隐藏字段放的是跳转时候传递的UserID   操作员11 -->
			<li><input type="hidden" id="userID" name="userID" value=""${sessionScope.myOperator.user.userID } ></li>
			<li><input type="hidden" id="landladyID" name="landladyID" ></li>
			<li><a href="javascript:void(0)" id="firstPage">首页</a></li>
			<li><a href="javascript:void(0)" id="pageUp">前一页</a></li>
			<li><label id="currentPage"></label><label>/</label><label
				id="pageCount"></label></li>
			<li><a href="javascript:void(0)" id="pageDown">后一页</a></li>
			<li><a href="javascript:void(0)" id="lastPage">末页</a></li>
		</ul>
		</div>
		<br />
	</form>
	<script type="text/javascript" src="../../js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
		$(function (){
			init();
		})
		function init(){
			//将请求或者session中保存的userID 
			//先计算有多少页
			countPageCount();
			//判断请求中是否有返回页码
			var curPage = <%= request.getParameter("currentPage")%>
			//这里必须  要将countPageCount方法设置为同步   不然取不到总页数  无法正确比较  显示数据
			var pageCount = $("#pageCount").html();
			if(curPage != null){
				//通过返回页码与当前总页数的比较 。若比当前总页数还要多   那么默认显示到最后一页
				if(curPage >= pageCount ){
					curPage = pageCount;
					$("#currentPage").html(pageCount);
				}
			}
			var currentPage = $("#currentPage").html();
			findLandladys(currentPage);
		}
		//通过当前页码显示 数据
		function findLandladys(currentPage){
			$.ajax({
				type : "POST",
				url : "findOnePageLandlady.do", 
				data : {
					"currentPage" : currentPage,
					},
				success : function(result) {
					countPageCount();
					var table;
					for (var i = 0; i < result.length; i++) {
						var registDate = new Date(result[i][4]);
						table = table
							+ "<tr id="+result[i][0]+"><td>"
							+ result[i][1]+ "</td><td>"+ result[i][2]
							+ "</td><td>"+result[i][3]+"</td>"
							+"<td>"+registDate.getFullYear()+"-"+(registDate.getUTCMonth()+1)+"-"+
									registDate.getUTCDate()+"</td>"
							+"<td><button type='button' class='ensureLandladyBtn btn btn-info'>审批</button></td></tr>";
					}
					$("#landladyTable tr:gt(0)").remove();
					$("#landladyTable").append(table);
				}
			});
		};
		//点击审批按钮
		$("#landladyTable").on("click",".ensureLandladyBtn",function(){
			var landladyID = $(this).parent().parent().attr("id");
			$("#landladyID").val(landladyID);
			var userID = $("#userID").val();
			var currentPage = $("#currentPage").html();
			window.location.href="conformLandlady.jsp?landladyID="+landladyID+"&currentPage="+currentPage;
		})
		//计算未通过审核的包租婆总共有多少页面
		function countPageCount() {
			var userID = $("#userID").val();
			$.ajax({
				type : "POST",
				url : "countLandladyPageCount.do", 
				async:false,
				data : {
				},
				success : function(pageCount) {
					$("#pageCount").html(pageCount);
					var currentPage = $("#currentPage").html();
					if(pageCount == 0 ){
						$("#currentPage").html(0);
					}else if(currentPage != "" && currentPage != 0){
						$("#currentPage").html(currentPage);
					}else{
						$("#currentPage").html(1);
					}
				}
			});
		}
		//分页的四个按钮功能  方法
		$("#firstPage").on("click", function() {
			var pageCount = $("#pageCount").html();
			if(pageCount == 0){
				$("#currentPage").html(0);
			}else{
				$("#currentPage").html(1);
			}
			findLandladys(1);
		})
		$("#pageUp").on("click", function() {
			var currentPage = $("#currentPage").html();
			var pageCount = $("#pageCount").html();
			if (currentPage > 1) {
				currentPage = currentPage - 1;
			} else if(pageCount == 0){
				currentPage = 0;
			}
			$("#currentPage").html(currentPage);
			findLandladys(currentPage);
		})
		//下一页
		$("#pageDown").on("click", function() {
			var currentPage = $("#currentPage").html();
			var pageCount = $("#pageCount").html();
			if (currentPage >= pageCount) {
				$("#currentPage").html(pageCount);
			} else {
				var newPage = new Number(currentPage)+1;
				$("#currentPage").html(newPage);
			}
			currentPage = $("#currentPage").html();
			findLandladys(currentPage);
		})
		$("#lastPage").on("click", function() {
			var pageCount = $("#pageCount").html();
			$("#currentPage").html(pageCount);
			findLandladys(pageCount);
		})
		</script>
</body>
</html>